<html>
<head><meta charset="utf-8"><title>Standard leak methods · t-libs · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/index.html">t-libs</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Standard.20leak.20methods.html">Standard leak methods</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="207768551"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Standard%20leak%20methods/near/207768551" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Ashley Mannix <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Standard.20leak.20methods.html#207768551">(Aug 23 2020 at 11:25)</a>:</h4>
<p>Hey all! Would anybody care to look at this RFC for standardising leaking/raw methods on containers? I’ve addressed some feedback but I don’t think it’s the sort RFC that’s got the pizazz to attract any attention on its own 😊 <a href="https://github.com/rust-lang/rfcs/pull/2969">https://github.com/rust-lang/rfcs/pull/2969</a></p>



<a name="207772836"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Standard%20leak%20methods/near/207772836" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Standard.20leak.20methods.html#207772836">(Aug 23 2020 at 13:20)</a>:</h4>
<p><span class="user-mention" data-user-id="204346">@Ashley Mannix</span> The thing that bothers me the most is that "leak" is definitely the wrong word to use for an operation that is supposed to be reversible.</p>



<a name="207782291"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Standard%20leak%20methods/near/207782291" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Ashley Mannix <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Standard.20leak.20methods.html#207782291">(Aug 23 2020 at 17:11)</a>:</h4>
<p><span class="user-mention" data-user-id="143274">@Amanieu</span> hmm, <code>Box::leak</code> is already reversible, and that’s how we use it in <code>LinkedList</code></p>



<a name="208471995"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Standard%20leak%20methods/near/208471995" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Standard.20leak.20methods.html#208471995">(Aug 30 2020 at 06:52)</a>:</h4>
<p>there's <code>Box::leak</code> and there's <code>Box::into_raw</code></p>



<a name="208471996"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Standard%20leak%20methods/near/208471996" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Standard.20leak.20methods.html#208471996">(Aug 30 2020 at 06:52)</a>:</h4>
<p>the former return a <code>'static</code> reference, the latter a raw pointer</p>



<a name="208472008"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Standard%20leak%20methods/near/208472008" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Standard.20leak.20methods.html#208472008">(Aug 30 2020 at 06:53)</a>:</h4>
<p>I think that makes sense; you should use the former if you truly intend to leak it and need a reference that lives forever for some purpose, and use the latter if you are doing unsafe stuff and are probably later going to do <code>from_raw</code> or so and make sure there is no actual leak.</p>



<a name="208473483"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Standard%20leak%20methods/near/208473483" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Ashley Mannix <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Standard.20leak.20methods.html#208473483">(Aug 30 2020 at 07:40)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> Are you thinking the existing scheme of <code>leak</code> and <code>into_raw</code>/<code>from_raw</code> using raw pointers is complete enough that we don’t need another pair of methods for <code>NonNull</code>?</p>



<a name="208473855"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Standard%20leak%20methods/near/208473855" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Standard.20leak.20methods.html#208473855">(Aug 30 2020 at 07:55)</a>:</h4>
<p>hm, fair, I keep forgetting about <code>NonNull</code>. that's annoying, having to have both that and raw pointers :/</p>



<a name="208491021"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Standard%20leak%20methods/near/208491021" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Standard.20leak.20methods.html#208491021">(Aug 30 2020 at 15:54)</a>:</h4>
<p>Also keep in mind that with custom allocators the lifetime will change to <code>'a</code> where <code>A: 'a</code>.</p>



<a name="208495032"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Standard%20leak%20methods/near/208495032" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Ashley Mannix <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Standard.20leak.20methods.html#208495032">(Aug 30 2020 at 17:18)</a>:</h4>
<p>Yeh, that RFC is trying to come up with a <code>NonNull</code>-based extension to the way we already use raw pointers on containers that makes it look like we totally meant it that way all along</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>